package com.mes.service.manu;

import com.yy.base.common.dao.Dao;
import com.yy.base.common.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class DiyListService extends BaseService {
	@Autowired
	private Dao dao;


	//根据RFID带出对应明细信息
	public List<Map<String,Object>> getPhotoLists(String code) {

		String sql = "SELECT  " +
				"  zy.CODE AS ZYCODE,  " +
				"  wl.NAME AS WLNAME,  " +
				"  ys.NAME AS YSNAME,   " +
				"  jh.color as COLORNAME, " +
				"  bw.name as BWNAME,  " +
				"  zt.NAME AS ZTNAME,  " +
				"  diy.foot_type AS FOOTTYPE,  " +
				"  diy.type AS DIYTYPE,  " +
				"  diy.font_text AS TEXT,  " +
				"  zygx.STATUS AS ZYSTATUS,  " +
				"  zygx.Emeso_Job_Order_Exe_id AS EXEIDS,  " +
				"  ( SELECT a.STATUS FROM Emeso_Job_Order_Exe a WHERE a.route_no = zygx.route_no - 10 AND a.emeso_job_order_id = zy.Emeso_Job_Order_id ) AS statuss,  " +
				"  diy.position AS WEIZHI,  " +
				"  diy.pic_path AS PICPATH,  " +
				"  diy.icon_path AS ICONPATH   " +
				"FROM  " +
				"  Emeso_Job_Order zy,  " +
				"  Emeso_Job_Order_Exe zygx,  " +
				"  emes_process gx,  " +
				"  emes_processopr gxm,  " +
				"  m_product wl,  " +
				"  emes_component bw,   " +
				"  emeso_manuorder sc,  " +
				"  emesp_planorder jh, " +
				"  emeso_manuorder_diy diy  " +
				"  LEFT JOIN Emes_Font zt ON zt.Emes_Font_Id = diy.Emes_Font_Id  " +
				"  LEFT JOIN Emes_Color ys ON ys.Emes_Color_Id = diy.Emes_Color_Id   " +
				"WHERE  " +
				"  zy.emeso_job_order_id = zygx.emeso_job_order_id   " +
				"  AND zygx.emes_process_id = gx.emes_process_id   " +
				"  AND zy.m_product_id = wl.m_product_id    " +
				"  and zy.emeso_manuorder_id = sc.emeso_manuorder_id  " +
				"  and sc.emesp_planorder_id = jh.emesp_planorder_id " +
				"  AND zy.emeso_manuorder_id = diy.emeso_manuorder_id   " +
				"  and gx.emes_processopr_id = gxm.emes_processopr_id  " +
				"  and diy.emes_component_id = bw.emes_component_id  " +
				"  AND gxm.code = 'DIY'   " +
				"  AND zy.CODE = ?  ";

		return dao.query(sql, code );
	}

	//修改工序的执行状态开工
	@SuppressWarnings("unchecked")
	public boolean UpdateExeBeginStatus(String Ids, String status) {
		boolean result = false;


		String sql =  "UPDATE Emeso_Job_Order_Exe SET status = ?, Exe_Date_From = now()  WHERE  Emeso_Job_Order_Exe_id = ? ";

		result = dao.executeSql(sql, status,Ids) > 0;

		return result;
	}

	//修改工序的执行状态为完工
	@SuppressWarnings("unchecked")
	public boolean UpdateExeEndStatus(String Ids, String status) {
		boolean result = false;


		String sql =  "UPDATE Emeso_Job_Order_Exe SET status = ?, Exe_Date_To = now()  WHERE  Emeso_Job_Order_Exe_id = ? ";

		result = dao.executeSql(sql, status,Ids) > 0;

		return result;
	}
}